import request from '@/utils/request'

/**
 * 添加购物车
 */
export function addCart(data: AnyObject) {
	if (uni.getStorageSync('wapShopMember')) {
		data.userId = uni.getStorageSync('wapShopMember').id;
	}
	return request.post(`trade/cart/addReserve`, data, { isYuDao: true })

}

/**
 * 编辑购物车数量
 */
export function editCart(data: AnyObject) {
	if (uni.getStorageSync('wapShopMember')) {
		data.userId = uni.getStorageSync('wapShopMember').id;
	}
	// return request.put(`shop/cart`, data)
	return request.put(`trade/cart/update-reserve`, data, { isYuDao: true, isPutQs: false })

}

/**
 * 删除购物车
 */
export function deleteCart(data: AnyObject) {
	if (uni.getStorageSync('wapShopMember')) {
		data.userId = uni.getStorageSync('wapShopMember').id;
	}
	// return request.put(`shop/cart/delete`, data)
	return request.delete(`trade/cart/delete?ids=${data.ids}&userId=${data.userId}`, {}, { isYuDao: true })

}

/**
 * 清空购物车
 */
export function clearCart() {
	return request.delete(`shop/cart/clear`)
}

/**
 * 获取购物车列表
 */
export function getCartList(params: Record<string, any>) {
	if (uni.getStorageSync('wapShopMember')) {
		params.userId = uni.getStorageSync('wapShopMember').id;
	}
	return request.get(`trade/cart/listReserve`, params, { isYuDao: true })

}

/**
 * 获取购物车商品列表
 */
export function getCartGoodsList(params: Record<string, any>) {
	if (uni.getStorageSync('wapShopMember')) {
		params.userId = uni.getStorageSync('wapShopMember').id;
	}
	return request.get(`trade/cart/listReserve`, params, { isYuDao: true })

}




